package me.bay.gt.java;

import me.bay.gt.java.beans.Klass;
import me.bay.gt.java.beans.School;
import me.bay.gt.java.beans.Student;
import me.bay.gt.java.config.AppConfig;
import me.bay.gt.java.service.ServiceA;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Main {
    public static void main(String[] args) {
//        ApplicationContext context = method2();
        ApplicationContext context = method1();

        School school = context.getBean(School.class);
        school.ding();
        Klass class1 = context.getBean(Klass.class);
        class1.dong();
        Student student1 = context.getBean("student1", Student.class);
        student1.print();
        ServiceA serviceA = context.getBean(ServiceA.class);
        serviceA.workWithB();
    }

    private static ApplicationContext method1() {
        return new ClassPathXmlApplicationContext("classpath:/applicationContext.xml");
    }

    private static ApplicationContext method2() {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
        context.register(AppConfig.class);
        context.scan("me.bay.gt.java.service");
        context.refresh();
        return context;
    }
}
